[Operating System] Virtual Memory Organization
Virtual Memory Organization
Virtual memory concept
- Concept
- A technique that allows the execution of processes that are not completely in memory
- Partition each user’s program into multiple blocks
- Load into memory the blocks that is necessary at each time during execution
- Noncontiguous allocation
- Logical memory size is not constrained by the amount of physical memory that is available
- Separation of logical memory as perceived by users from physical memory
- A technique that allows the execution of processes that are not completely in memory
- Benefits
- Easier programming
- Programmer no longer needs to worry about the amount of physical memory available
- Higher multiprogramming degree
- Increase in CPU utilization and throughput (not in response time and turnaround time)
- Less I/O for loading and swapping processes into memory
- Faster execution of processes
- Easier programming
- Drawbacks
- Address mapping overhead
- Page fault handling overhead
- Should be carefully used in real-time (embedded) systems
- Methods
- Paging (Demand paging)
- Partition each user’s program into same size blocks
- Segmentation
- Partition each user’s program into logical blocks of different sizes
- Hybrid paging/segmentation
- Paging (Demand paging)
Address Mapping
Case: Contiguous allocation
- Executable memory images can be built by relocation (Load-time binding)
- Relative address
- Start address of the program: 0
- Relative address
- Relocation
- Transforming relative addresses (address constants) in the program to the corresponding physical addresses according to the allocation address of the program
Case: Noncontiguous allocation
- Virtual address = relative address
- Real address = absolute(physical) address
- Address mapping
- Difficult to implement load-time binding
- Virtual address to real address transformation at run-time
Notes
- Virtual address space
- Refers to the logical (virtual) view of how a process is stored in memory
- Sparse address space
- Virtual address space that includes holes
- Beneficial because the holes can be filled as the stack or heap segments grow or can be used when we wish to dynamically link libraries (shared objects) during program execution
- Shared library in virtual memory
Block mapping
Block mapping
- Block mapping
- Partition user programs into blocks
- Maintain address mapping information for each block of the program
- Block map table
- Keep virtual address, corresponding real address, and other information, for each block of the program
Virtual address v = (b, d)
- b = block number
- d = displacement(offset) in a block
Block map table
- Maintains address mapping information
- One BMT for each process in the system
- In the kernel space
Block mapping procedure
Demand Paging
Paging System
Paging (Demand paging) system
- Partition the program into the same size blocks (pages)
- Loading of executable program
- Initially, load pages only as they are needed
- During execution, load the pages when they are demanded (referenced)
- Pages that are never accessed are never loaded into physical memory
- 필요 없는 페이지는 다시 내보내기도 한다.
Terminologies
- Page
- Page frame
- Pager
- Swaps a page into memory when the page is referenced
- Concerned with the individual pages of a process
- Swapper
- Manipulates entire process
- Swaps entire process into memory
Characteristics of paging system
- No logical partition of the program
- Simple and efficient
- Used in most operating systems
- Complex for sharing and protection
Address mapping
- Virtual address v = (p, d) in paging systems
- p = page number
- d = displacement(offset)
- Address mapping
- Uses PMT (Page Map Table)
- Address mapping mechanisms
- Direct mapping
- Associative mapping
- TLB(Translation Look-aside Buffer)
- Hybrid direct/associative mapping
- Page map table
Address Mapping in Paging S.
Direct mapping
- Similar to block mapping mechanisms
- Assumptions
- PMT resides in kernel space of main memory
- PMT entry size = entrySize
- Page size = pageSize
Problems in direct mapping
- Doubles the number of memory accesses during execution of the program
- Performance degradation
- PMT size
Solutions
- Associative mapping (TLB)
- Implement the PMT using the dedicated registers or cache memories
Associative mapping
- TLB(Translation Look-aside Buffer)
- Associative high-speed memory
- Parallel search on PMT
- Low overhead, high speed
- Expensive hardware
Hybrid direct/associative mapping
- Uses direct mapping and associative mapping, simultaneously
- Low hardware cost
- Take advantage of associative mapping
- Small TLB
- Full PMT: maintained in kernel space of the memory
- Subset of PMT entries: maintained in TLB
- Entries of the recently used pages
Locality - 한 번 접근된 페이지는 또 다시 접근될 가능성이 많다.
Effective memory access time (EAT)
- TLB search: 20ns
- Memory access time: 100ns
- TLB hit ratio: 80%
- EAT = 0.8(20 + 100) + 0.2(20 + 100 + 100) = 140ns
- 40% slowdown in memory access time
- TLB hit ratio: 98%
- EAT = 0.98(20 + 100) + 0.02(20 + 100 + 100) = 122ns
- 22% slowdown in memory access time
Other page table structures
- Page-table registers
- Hierarchical paging
- Hashed page table
- Inverted page table
Issues in Demand Paging
Page Sharing
Sharable pages
- Procedure pages
- Pure code (reentrant code)
- Data page
- Read-only data
- Sharable without any restriction
- Read-write data
- Sharable under the concurrency control mechanism
- Read-only data
Page Fault Handling
- A crucial requirement for demand paging
- Restart any instruction after a page fault
- Example (steps to execute and instruction)
Performance of Paging System
Effective access time
- Memory access time
- 10 ~ 200 nanoseconds (Assume 100ns)
- Average paging service time: about 8 milliseconds
- Page fault rate: p (0 p 1)
- EAT(Effective Access Time)
- EAT = (1-p)ma + ppagingTime
- = (1-p)100 + p8,000,000
- = 100 + 7,999,900p
- When p = 1/1000, EAT = 8.1 microseconds ( 80ma)
- EAT = (1-p)ma + ppagingTime
- If we want less than 10% degradation,
- EAT = 100 + 7,999,900p < 110
- p < 0.00000125 ( 1/800,000)
….
Segmentation & Hybrid Paging/Segmentation
Segmentation system
- Partition user program into logical blocks with possibly different sizes
- Segment
- Logically partitioned block
- Characteristics
- Pre-partition of main memory is not good in this case
- Main memory management can be done similarly to VPM
- Easy segment sharing and protection
- Larger overhead in address mapping and memory management
Address mapping
- Virtual address in segmentation system: v = (s, d)
- s = segment number
- d = displacement in a segment
- SMT(Segment Map Table)
- Address mapping mechanisms
- Similar to them of paging system
Address Mapping in Seg. System
Direct mapping
- Assumptions
- SMT in kernel space of memory
- Entry size of SMT = entrySize
Memory Mgm’t in Seg. Systems
- Memory management
- Similar to VPM
- Initially, 1 partition in memory
- Placement strategies
- First fit
- Best fit
- Worst fit
- Next fit
Hybrid Paging/Segmentation
Paging System
- Advantages
- Simple and low overhead
- Disadvantages
- No logical concept in partitioning programs
- Complicated page sharing mechanism
Segmentation System
- Advantages
- Logical concept in partitioning programs
- Simple and easy sharing mechanism
- Disadvantages
- Management overhead
Hybrid paging/segmentation
- Take advantages of the paging/segmentation systems
- Program partition
- User program is partitioned into logical segments
- Each segment is partitioned again into pages
- Loading
- Loading unit: page
Address mapping
- Virtual address in hybrid systems: v = (s, p, d)
- s = segment number
- p = page number in a segment
- d = offset in a page
- Uses both SMT and PMT
- One SMT for each process
- One PMT for each segment in the program
- Address mapping
- Direct, associative, etc.
- Memory
- Pre-partitioned into page frames
Summary
- Virtual memory concept
- Address mapping
- Demand paging
- Address mapping
- Direct mapping, associative mapping, hybrid mapping, page table registers, hierarchical paging, hashed page table, inverted page table
- Issues in demand paging
- Page sharing, page fault handling, performance, copy-on-write, memory-mapped files, kernel memory allocation
- Address mapping
- Segmentation
- Hybrid paging/segmentation
댓글남기기